/*
 * Copyright (c) 2013. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.jspx.txweb.action;

import com.jspx.boot.environment.Environment;
import com.jspx.boot.sign.LanguageRes;
import com.jspx.txweb.annotation.HttpMethod;
import com.jspx.txweb.annotation.Operate;
import com.jspx.txweb.annotation.Safety;
import com.jspx.txweb.table.ActionLog;
import com.jspx.txweb.view.ActionLogView;
import com.jspx.utils.ArrayUtil;

/**
 * Created with IntelliJ IDEA.
 * User: yuan
 * Date: 13-10-16
 * Time: 下午10:43
 *
 */
@HttpMethod(caption = "日志管理")
public class ActionLogAction extends ActionLogView {
    private Long[] idArray = null;
    @Safety(request = false)
    public void setIdArray(Long[] idArray) {
        this.idArray = idArray;
    }


    @Operate(caption="删除")
    public void delete() throws Exception
    {
        setActionResult(ROC);
        Long[] ids = getLongArray("id",idArray);
        if (ArrayUtil.isEmpty(ids))
        {
            addFieldInfo(Environment.warningInfo, language.getLang(LanguageRes.needSelect));
            return;
        }
        if (actionLogDAO.delete(ids))
        {
            addActionMessage(language.getLang(LanguageRes.deleteSuccess));
        } else
        {
            addActionMessage(language.getLang(LanguageRes.deleteFailure));
        }
    }

    @Operate(caption="清除一年前")
    public void deleteYear() throws Exception
    {
        setActionResult(ROC);
        if (actionLogDAO.deleteYearBefore(1)>=0)
        {
            addActionMessage(language.getLang(LanguageRes.deleteSuccess));
        } else
        {
            addActionMessage(language.getLang(LanguageRes.deleteFailure));
        }
    }

    @Operate(caption="清空")
    public void clear() throws Exception
    {
        setActionResult(ROC);
        if (actionLogDAO.clear()>=0)
        {
            addActionMessage(language.getLang(LanguageRes.deleteSuccess));
        } else
        {
            addActionMessage(language.getLang(LanguageRes.deleteFailure));
        }
    }

    @Override
    public String execute() throws Exception {
        if (isMethodInvoked())
        {
            actionLogDAO.evict(ActionLog.class);
        }
        return super.execute();
    }
}

//2104


